/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.DynamicGroup;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.GuestAccount;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.GroupMemberEmailAddrs;
/*     */ import com.zimbra.cs.account.Provisioning.GroupMembership;
/*     */ import com.zimbra.cs.account.Provisioning.MemberOf;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.ldap.entry.LdapAccount;
/*     */ import com.zimbra.cs.account.ldap.entry.LdapDynamicGroup;
/*     */ import com.zimbra.cs.gal.GalGroupMembers;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest.Sequencer;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest.SkipTestReason;
/*     */ import com.zimbra.qa.unittest.prov.Verify;
/*     */ import java.util.Collections;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvDynamicGroup
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   private static ProvTest.Sequencer seq;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  65 */     provUtil = new LdapProvTestUtil();
/*  66 */     prov = provUtil.getProv();
/*  67 */     domain = provUtil.createDomain(baseDomainName(), null);
/*  68 */     seq = new ProvTest.Sequencer();
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception
/*     */   {}
/*     */   
/*     */   private DynamicGroup createDynamicGroup(String localPart) throws Exception
/*     */   {
/*  77 */     return provUtil.createDynamicGroup(localPart, domain);
/*     */   }
/*     */   
/*     */   private DynamicGroup createDynamicGroup(String localPart, Map<String, Object> attrs) throws Exception
/*     */   {
/*  82 */     return provUtil.createDynamicGroup(localPart, domain, attrs);
/*     */   }
/*     */   
/*     */   private void deleteDynamicGroup(DynamicGroup group) throws Exception {
/*  86 */     provUtil.deleteDynamicGroup(group);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void createDynamicGroup()
/*     */     throws Exception
/*     */   {
/*  94 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/*     */ 
/*  97 */     Server homeServer = group.getServer();
/*  98 */     Assert.assertNotNull(homeServer);
/*     */     
/* 100 */     deleteDynamicGroup(group);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void deleteDynamicGroup()
/*     */     throws Exception
/*     */   {
/* 108 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart());
/* 109 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*     */     
/*     */ 
/* 112 */     prov.addGroupMembers(group, new String[] { acct.getName() });
/*     */     
/* 114 */     Assert.assertTrue(acct.getMultiAttrSet("zimbraMemberOf").contains(group.getId()));
/*     */     
/*     */ 
/* 117 */     deleteDynamicGroup(group);
/*     */     
/*     */ 
/* 120 */     acct = prov.get(Key.AccountBy.id, acct.getId());
/* 121 */     Assert.assertFalse(acct.getMultiAttrSet("zimbraMemberOf").contains(group.getId()));
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void renameDynamicGroup()
/*     */     throws Exception
/*     */   {
/* 129 */     String origLocalpart = genGroupNameLocalPart();
/* 130 */     Group group = createDynamicGroup(origLocalpart);
/*     */     
/* 132 */     String groupId = group.getId();
/*     */     
/* 134 */     String newLocalpart = origLocalpart + "-new";
/* 135 */     String newName = TestUtil.getAddress(newLocalpart, domain.getName());
/*     */     
/* 137 */     prov.renameGroup(groupId, newName);
/*     */     
/* 139 */     group = prov.getGroup(Key.DistributionListBy.name, newName);
/* 140 */     Assert.assertEquals(groupId, group.getId());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void zimbraIsACLGroup_and_memeberURL_1()
/*     */     throws Exception
/*     */   {
/* 156 */     Map<String, Object> attrs = new HashMap();
/* 157 */     attrs.put("memberURL", "blah");
/* 158 */     attrs.put("zimbraIsACLGroup", "FALSE");
/* 159 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart(seq), attrs);
/* 160 */     Assert.assertEquals(Boolean.valueOf(false), Boolean.valueOf(group.isIsACLGroup()));
/*     */     
/* 162 */     String errCode = null;
/* 163 */     attrs = new HashMap();
/* 164 */     attrs.put("memberURL", "blah");
/*     */     try {
/* 166 */       createDynamicGroup(genGroupNameLocalPart(seq), attrs);
/*     */     } catch (ServiceException e) {
/* 168 */       errCode = e.getCode();
/*     */     }
/* 170 */     Assert.assertEquals("ldap.OBJECT_CLASS_VIOLATION", errCode);
/*     */     
/* 172 */     errCode = null;
/* 173 */     attrs = new HashMap();
/* 174 */     attrs.put("memberURL", "blah");
/* 175 */     attrs.put("zimbraIsACLGroup", "TRUE");
/*     */     try {
/* 177 */       createDynamicGroup(genGroupNameLocalPart(seq), attrs);
/*     */     } catch (ServiceException e) {
/* 179 */       Assert.assertTrue("Unexpected Exception e thrown", false);
/* 180 */       errCode = e.getCode();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void zimbraIsACLGroup_and_memeberURL_2()
/*     */     throws Exception
/*     */   {
/* 190 */     Map<String, Object> attrs = new HashMap();
/*     */     
/* 192 */     attrs.put("zimbraIsACLGroup", "TRUE");
/* 193 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart(seq), attrs);
/* 194 */     Assert.assertEquals(Boolean.valueOf(true), Boolean.valueOf(group.isIsACLGroup()));
/*     */     
/* 196 */     String errCode = null;
/* 197 */     attrs = new HashMap();
/* 198 */     attrs.put("zimbraIsACLGroup", "FALSE");
/*     */     try {
/* 200 */       createDynamicGroup(genGroupNameLocalPart(seq), attrs);
/*     */     } catch (ServiceException e) {
/* 202 */       errCode = e.getCode();
/*     */     }
/* 204 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void zimbraIsACLGroup_and_memeberURL_3()
/*     */     throws Exception
/*     */   {
/* 213 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/*     */ 
/* 216 */     String errCode = null;
/*     */     Map<String, Object> attrs;
/* 218 */     try { attrs = new HashMap();
/* 219 */       attrs.put("zimbraIsACLGroup", "TRUE");
/* 220 */       prov.modifyAttrs(group, attrs, true);
/*     */     } catch (ServiceException e) {
/* 222 */       errCode = e.getCode();
/*     */     }
/* 224 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */     
/* 226 */     errCode = null;
/*     */     try {
/* 228 */       attrs = new HashMap();
/* 229 */       attrs.put("zimbraIsACLGroup", "TRUE");
/* 230 */       attrs.put("memberURL", "blah");
/* 231 */       prov.modifyAttrs(group, attrs, true);
/*     */     } catch (ServiceException e) {
/* 233 */       errCode = e.getCode();
/*     */     }
/* 235 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void zimbraIsACLGroup_and_memeberURL_4()
/*     */     throws Exception
/*     */   {
/* 243 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/*     */ 
/* 246 */     String errCode = null;
/*     */     try {
/* 248 */       Map<String, Object> attrs = new HashMap();
/* 249 */       attrs.put("memberURL", "blah");
/* 250 */       prov.modifyAttrs(group, attrs, true);
/*     */     } catch (ServiceException e) {
/* 252 */       errCode = e.getCode();
/*     */     }
/* 254 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void zimbraIsACLGroup_and_memeberURL_5()
/*     */     throws Exception
/*     */   {
/* 262 */     Map<String, Object> attrs = new HashMap();
/* 263 */     attrs.put("memberURL", "foo");
/* 264 */     attrs.put("zimbraIsACLGroup", "FALSE");
/* 265 */     DynamicGroup group = createDynamicGroup(genGroupNameLocalPart(seq), attrs);
/* 266 */     Assert.assertEquals(Boolean.valueOf(false), Boolean.valueOf(group.isIsACLGroup()));
/*     */     
/* 268 */     attrs = new HashMap();
/* 269 */     attrs.put("memberURL", "bar");
/* 270 */     prov.modifyAttrs(group, attrs, true);
/* 271 */     Assert.assertEquals("bar", group.getMemberURL());
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void memberAttrViaSlapdOverlay()
/*     */     throws Exception
/*     */   {
/* 279 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DYNAMIC_GROUP_OVERLAY);
/*     */     
/* 281 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 283 */     Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
/* 284 */     Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
/*     */     
/* 286 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName() });
/*     */     
/*     */ 
/* 289 */     group = prov.getGroup(Key.DistributionListBy.id, group.getId());
/* 290 */     String[] memberDNs = group.getMultiAttr("member");
/*     */     
/* 292 */     Set<String> expected = Sets.newHashSet(new String[] { ((LdapAccount)acct1).getDN(), ((LdapAccount)acct2).getDN(), "cn=external," + ((LdapDynamicGroup)group).getDN() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 297 */     Verify.verifyEquals(expected, memberDNs);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void addMembersBasic()
/*     */     throws Exception
/*     */   {
/* 305 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 307 */     Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
/* 308 */     Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
/* 309 */     String extAddr1 = "user1@external.com";
/* 310 */     String extAddr2 = "user2@external.com";
/*     */     
/* 312 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/*     */ 
/* 315 */     String[] members = prov.getGroupMembers(group);
/*     */     
/* 317 */     Set<String> expected = Sets.newHashSet(new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/*     */ 
/* 320 */     Verify.verifyEquals(expected, members);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void addMembersInvalidAddr()
/*     */     throws Exception
/*     */   {
/* 328 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 330 */     String addr = "bogus";
/*     */     
/* 332 */     String errCode = null;
/*     */     try {
/* 334 */       prov.addGroupMembers(group, new String[] { addr });
/*     */     } catch (ServiceException e) {
/* 336 */       errCode = e.getCode();
/*     */     }
/* 338 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void addMemberExisting()
/*     */     throws Exception
/*     */   {
/* 346 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 348 */     Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
/* 349 */     Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
/* 350 */     String extAddr1 = "user1@external.com";
/* 351 */     String extAddr2 = "user2@external.com";
/*     */     
/* 353 */     Set<String> expected = Sets.newHashSet(new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/*     */ 
/* 356 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/* 358 */     String[] members = prov.getGroupMembers(group);
/* 359 */     Verify.verifyEquals(expected, members);
/*     */     
/*     */ 
/* 362 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/* 364 */     members = prov.getGroupMembers(group);
/* 365 */     Verify.verifyEquals(expected, members);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void addMembersInternalAddress()
/*     */     throws Exception
/*     */   {
/* 373 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 375 */     String otherDynGroupLocalPart = genGroupNameLocalPart("other-dynamic");
/* 376 */     Group otherDynamicGroup = createDynamicGroup(otherDynGroupLocalPart);
/* 377 */     Group otherStaticGroup = provUtil.createDistributionList(genGroupNameLocalPart("other-static"), domain);
/*     */     
/* 379 */     String errCode = null;
/*     */     try {
/* 381 */       prov.addGroupMembers(group, new String[] { otherDynamicGroup.getName() });
/*     */     } catch (ServiceException e) {
/* 383 */       errCode = e.getCode();
/*     */     }
/* 385 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */     
/* 387 */     errCode = null;
/*     */     try {
/* 389 */       prov.addGroupMembers(group, new String[] { otherStaticGroup.getName() });
/*     */     } catch (ServiceException e) {
/* 391 */       errCode = e.getCode();
/*     */     }
/* 393 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */     
/*     */ 
/* 396 */     errCode = null;
/*     */     try {
/* 398 */       String addr = otherDynGroupLocalPart + ".__internal__@" + domain.getName();
/* 399 */       prov.addGroupMembers(group, new String[] { addr });
/*     */     } catch (ServiceException e) {
/* 401 */       errCode = e.getCode();
/*     */     }
/* 403 */     Assert.assertEquals("service.INVALID_REQUEST", errCode);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void removeMembersBasic()
/*     */     throws Exception
/*     */   {
/* 411 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 413 */     Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
/* 414 */     Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
/* 415 */     String extAddr1 = "user1@external.com";
/* 416 */     String extAddr2 = "user2@external.com";
/*     */     
/* 418 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/*     */ 
/* 421 */     String[] members = prov.getGroupMembers(group);
/*     */     
/* 423 */     Set<String> expected = Sets.newHashSet(new String[] { acct1.getName(), acct2.getName(), extAddr1, extAddr2 });
/*     */     
/* 425 */     Verify.verifyEquals(expected, members);
/*     */     
/* 427 */     prov.removeGroupMembers(group, new String[] { acct1.getName(), extAddr1 });
/* 428 */     members = prov.getGroupMembers(group);
/* 429 */     expected = Sets.newHashSet(new String[] { acct2.getName(), extAddr2 });
/* 430 */     Verify.verifyEquals(expected, members);
/*     */     
/*     */ 
/* 433 */     prov.removeGroupMembers(group, new String[] { group.getName() });
/* 434 */     prov.removeGroupMembers(group, new String[] { "bogus" });
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void getGroupMembership()
/*     */     throws Exception
/*     */   {
/* 442 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/* 443 */     Group otherDynamicGroup = createDynamicGroup(genGroupNameLocalPart("other-dynamic"));
/* 444 */     Group otherStaticGroup = provUtil.createDistributionList(genGroupNameLocalPart("other-static"), domain);
/*     */     
/* 446 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*     */     
/* 448 */     String externalAddr = "user@external.com";
/* 449 */     GuestAccount guestAcct = new GuestAccount(externalAddr, null);
/*     */     
/* 451 */     prov.addGroupMembers(group, new String[] { acct.getName(), externalAddr });
/* 452 */     prov.addGroupMembers(otherDynamicGroup, new String[] { acct.getName(), externalAddr });
/* 453 */     prov.addGroupMembers(otherStaticGroup, new String[] { acct.getName(), externalAddr });
/*     */     
/* 455 */     Set<String> expectedMemberOf = Sets.newHashSet(new String[] { Verify.makeResultStr(new Object[] { group.getId(), Boolean.FALSE }), Verify.makeResultStr(new Object[] { otherDynamicGroup.getId(), Boolean.FALSE }), Verify.makeResultStr(new Object[] { otherStaticGroup.getId(), Boolean.FALSE }) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 460 */     Set<String> expectedIds = Sets.newHashSet(new String[] { Verify.makeResultStr(new Object[] { group.getId() }), Verify.makeResultStr(new Object[] { otherDynamicGroup.getId() }), Verify.makeResultStr(new Object[] { otherStaticGroup.getId() }) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 469 */     Provisioning.GroupMembership membership = prov.getGroupMembership(acct, false);
/* 470 */     List<Provisioning.MemberOf> memberOfList = membership.memberOf();
/* 471 */     List<String> groupIdList = membership.groupIds();
/*     */     
/* 473 */     Set<String> actualMemberOf = Sets.newHashSet();
/* 474 */     for (Provisioning.MemberOf memberOf : memberOfList) {
/* 475 */       actualMemberOf.add(Verify.makeResultStr(new Object[] { memberOf.getId(), Boolean.valueOf(memberOf.isAdminGroup()) }));
/*     */     }
/*     */     
/* 478 */     Set<String> actualIds = Sets.newHashSet();
/* 479 */     for (String id : groupIdList) {
/* 480 */       actualIds.add(Verify.makeResultStr(new Object[] { id }));
/*     */     }
/*     */     
/* 483 */     Verify.verifyEquals(expectedMemberOf, actualMemberOf);
/* 484 */     Verify.verifyEquals(expectedIds, actualIds);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 489 */     membership = prov.getGroupMembership(guestAcct, false);
/* 490 */     memberOfList = membership.memberOf();
/* 491 */     groupIdList = membership.groupIds();
/*     */     
/* 493 */     actualMemberOf = Sets.newHashSet();
/* 494 */     for (Provisioning.MemberOf memberOf : memberOfList) {
/* 495 */       actualMemberOf.add(Verify.makeResultStr(new Object[] { memberOf.getId(), Boolean.valueOf(memberOf.isAdminGroup()) }));
/*     */     }
/*     */     
/* 498 */     actualIds = Sets.newHashSet();
/* 499 */     for (String id : groupIdList) {
/* 500 */       actualIds.add(Verify.makeResultStr(new Object[] { id }));
/*     */     }
/*     */     
/* 503 */     Verify.verifyEquals(expectedMemberOf, actualMemberOf);
/* 504 */     Verify.verifyEquals(expectedIds, actualIds);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void galSearch()
/*     */     throws Exception
/*     */   {
/* 512 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/* 514 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/*     */     
/* 516 */     Account acct1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
/* 517 */     Account acct2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
/* 518 */     String externalAddr = "user@external.com";
/*     */     
/* 520 */     prov.addGroupMembers(group, new String[] { acct1.getName(), externalAddr });
/*     */     
/* 522 */     Set<String> galGroupMembers = GalGroupMembers.getGroupMembers(group.getName(), acct2);
/*     */     
/* 524 */     Set<String> expected = Sets.newHashSet(new String[] { acct1.getName(), externalAddr });
/* 525 */     Verify.verifyEquals(expected, galGroupMembers);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void externalAddrRemovedOnInternalAddrCreationCreation()
/*     */     throws Exception
/*     */   {
/* 535 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/* 536 */     String groupId = group.getId();
/*     */     
/* 538 */     String externalAddr1 = genGroupNameLocalPart("1") + "@" + domain.getName();
/* 539 */     String externalAddr2 = genGroupNameLocalPart("2") + "@" + domain.getName();
/* 540 */     String externalAddr3 = genGroupNameLocalPart("3") + "@" + domain.getName();
/* 541 */     String externalAddr4 = genGroupNameLocalPart("4") + "@" + domain.getName();
/* 542 */     String externalAddr5 = genGroupNameLocalPart("5") + "@" + domain.getName();
/* 543 */     String externalAddr6 = genGroupNameLocalPart("6") + "@" + domain.getName();
/* 544 */     String externalAddr7 = genGroupNameLocalPart("7") + "@" + domain.getName();
/* 545 */     String externalAddr8 = genGroupNameLocalPart("8") + "@" + domain.getName();
/* 546 */     String externalAddr9 = genGroupNameLocalPart("9") + "@" + domain.getName();
/*     */     
/* 548 */     prov.addGroupMembers(group, new String[] { externalAddr1, externalAddr2, externalAddr3, externalAddr4, externalAddr5, externalAddr6, externalAddr7, externalAddr8, externalAddr9 });
/*     */     
/*     */ 
/*     */ 
/* 552 */     String[] members = prov.getGroupMembers(group);
/*     */     
/* 554 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr1, externalAddr2, externalAddr3, externalAddr4, externalAddr5, externalAddr6, externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 562 */     Group newGroup = provUtil.createGroup(externalAddr1, false);
/*     */     
/*     */ 
/* 565 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 566 */     members = prov.getGroupMembers(group);
/* 567 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr2, externalAddr3, externalAddr4, externalAddr5, externalAddr6, externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 573 */     prov.addGroupAlias(newGroup, externalAddr2);
/* 574 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 575 */     members = prov.getGroupMembers(group);
/* 576 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr3, externalAddr4, externalAddr5, externalAddr6, externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 582 */     prov.renameGroup(newGroup.getId(), externalAddr3);
/* 583 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 584 */     members = prov.getGroupMembers(group);
/* 585 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr4, externalAddr5, externalAddr6, externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 593 */     newGroup = provUtil.createGroup(externalAddr4, true);
/* 594 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 595 */     members = prov.getGroupMembers(group);
/* 596 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr5, externalAddr6, externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 601 */     prov.addGroupAlias(newGroup, externalAddr5);
/* 602 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 603 */     members = prov.getGroupMembers(group);
/* 604 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr6, externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 609 */     prov.renameGroup(newGroup.getId(), externalAddr6);
/* 610 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 611 */     members = prov.getGroupMembers(group);
/* 612 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr7, externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 619 */     Account newAcct = provUtil.createAccount(externalAddr7);
/* 620 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 621 */     members = prov.getGroupMembers(group);
/* 622 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr8, externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 627 */     prov.addAlias(newAcct, externalAddr8);
/* 628 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 629 */     members = prov.getGroupMembers(group);
/* 630 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr9 }), members);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 635 */     prov.renameAccount(newAcct.getId(), externalAddr9);
/* 636 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 637 */     members = prov.getGroupMembers(group);
/* 638 */     Verify.verifyEquals(Collections.emptySet(), members);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void renameAccount()
/*     */     throws Exception
/*     */   {
/* 648 */     Group group = createDynamicGroup(genGroupNameLocalPart());
/* 649 */     String groupId = group.getId();
/*     */     
/* 651 */     Account acct = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
/* 652 */     String newAddr = TestUtil.getAddress(genAcctNameLocalPart("2"), domain.getName());
/*     */     
/* 654 */     prov.addGroupMembers(group, new String[] { acct.getName(), newAddr });
/* 655 */     String[] members = prov.getGroupMembers(group);
/*     */     
/* 657 */     Verify.verifyEquals(Sets.newHashSet(new String[] { acct.getName(), newAddr }), members);
/*     */     
/*     */ 
/* 660 */     Provisioning.GroupMembership membership = prov.getGroupMembership(acct, false);
/* 661 */     List<String> groupIdList = membership.groupIds();
/*     */     
/* 663 */     Assert.assertTrue(groupIdList.contains(groupId));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 668 */     prov.renameAccount(acct.getId(), newAddr);
/* 669 */     group = prov.getGroupBasic(Key.DistributionListBy.id, groupId);
/* 670 */     members = prov.getGroupMembers(group);
/*     */     
/* 672 */     Verify.verifyEquals(Sets.newHashSet(new String[] { newAddr }), members);
/*     */     
/*     */ 
/* 675 */     membership = prov.getGroupMembership(acct, false);
/* 676 */     groupIdList = membership.groupIds();
/*     */     
/* 678 */     Assert.assertTrue(groupIdList.contains(groupId));
/*     */   }
/*     */   
/*     */ 
/*     */   private void testGetMemberAddrs(boolean dynamic)
/*     */     throws Exception
/*     */   {
/* 685 */     Group group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
/*     */     
/* 687 */     Account acct1 = provUtil.createAccount(genAcctNameLocalPart(seq), domain);
/* 688 */     Account acct2 = provUtil.createAccount(genAcctNameLocalPart(seq), domain);
/* 689 */     String externalAddr1 = "user1@external.com";
/* 690 */     String externalAddr2 = "user2@external.com";
/*     */     
/* 692 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName(), externalAddr1, externalAddr2 });
/*     */     
/* 694 */     Provisioning.GroupMemberEmailAddrs addrs = prov.getMemberAddrs(group);
/* 695 */     Assert.assertNull(addrs.groupAddr());
/* 696 */     Verify.verifyEquals(Sets.newHashSet(new String[] { acct1.getName(), acct2.getName() }), addrs.internalAddrs());
/*     */     
/*     */ 
/* 699 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr1, externalAddr2 }), addrs.externalAddrs());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 706 */     group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
/* 707 */     prov.addGroupMembers(group, new String[] { acct1.getName(), acct2.getName() });
/*     */     
/* 709 */     addrs = prov.getMemberAddrs(group);
/* 710 */     Assert.assertEquals(group.getName(), addrs.groupAddr());
/* 711 */     Assert.assertNull(addrs.internalAddrs());
/* 712 */     Assert.assertNull(addrs.externalAddrs());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 717 */     group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
/* 718 */     prov.addGroupMembers(group, new String[] { externalAddr1, externalAddr2 });
/*     */     
/* 720 */     addrs = prov.getMemberAddrs(group);
/* 721 */     Assert.assertNull(addrs.groupAddr());
/* 722 */     Assert.assertNull(addrs.internalAddrs());
/* 723 */     Verify.verifyEquals(Sets.newHashSet(new String[] { externalAddr1, externalAddr2 }), addrs.externalAddrs());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 730 */     group = provUtil.createGroup(genGroupNameLocalPart(seq), domain, dynamic);
/* 731 */     addrs = prov.getMemberAddrs(group);
/* 732 */     Assert.assertEquals(group.getName(), addrs.groupAddr());
/* 733 */     Assert.assertNull(addrs.internalAddrs());
/* 734 */     Assert.assertNull(addrs.externalAddrs());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void getMemberAddrs()
/*     */     throws Exception
/*     */   {
/* 743 */     testGetMemberAddrs(true);
/* 744 */     testGetMemberAddrs(false);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvDynamicGroup.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */